package com.skwen.delivery.superdelivery.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.skwen.delivery.superdelivery.BaseActivity;
import com.skwen.delivery.superdelivery.MainActivity;
import com.skwen.delivery.superdelivery.R;
import com.skwen.delivery.superdelivery.login.LoginActivity;
import com.skwen.delivery.superdelivery.login.bean.User;
import com.skwen.delivery.superdelivery.myGreenDao.manager.UserDBManager;

import java.util.List;

/**
 * Created by skwen on 2017/9/28.
 * SuperDelivery
 */

public class WelcomActivity extends BaseActivity {


    private Handler mHandler = new Handler();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcom_layout);
        mHandler.postDelayed(() -> gotoOther(), 3000);

    }

    private void gotoOther() {

        UserDBManager userDbManager = UserDBManager.getInstance(this);
        List<User> list = userDbManager.queryUserList();
        if (list != null && list.size() > 0) {
            User mUser = list.get(0);
            if (mUser != null) {
                startActivity(new Intent(WelcomActivity.this, MainActivity.class));
                Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
                finish();
            } else {
                startActivity(new Intent(WelcomActivity.this, LoginActivity.class));
                finish();
            }
        } else {
            startActivity(new Intent(WelcomActivity.this, LoginActivity.class));
            finish();
        }
    }

}
